import React from "react";
import dayjs from "dayjs";

import type { DataAction, IProTableRef } from "@yaf/pro-ui";
import { getOnlineUserPageList } from "../../api";

export const getDataAction = (_: React.MutableRefObject<IProTableRef>): DataAction => ({
    fetchList: (params) => {
        const { page, pageSize, filter } = params;
        if(filter.dateRange){
          const [ startTime, endTime ] = filter.dateRange as dayjs.Dayjs[];
          filter.dateRange = JSON.stringify([startTime.format("YYYY-MM-DD"), endTime.format("YYYY-MM-DD")])
        }

        return getOnlineUserPageList(Object.assign({page,pageSize}, filter || {})).then((resp) => resp.data)
    },
    // deleteItems: (selectedRowKeys) => {
    //     return deleteOnlineUser(selectedRowKeys.map((item) => parseInt(item)))
    // },
})


